
#include "floatimage.H"

void main(int argc, char *argv[])
{
	
	floatimage specularImage;
	floatimage diffuseImage;

	diffuseImage.LoadPFM("sh0_h.pfm");
	specularImage.LoadPFM("SPEC_0022.pfm");
	floatimage output(specularImage.sizex,specularImage.sizey);

	float albedo[3] = {0,0,0};
	int sum = 0;

	for (int i=998;i<1024;i++)
	{
		for (int j=1370;j<1396;j++)
		{
			sum ++;

			albedo[0] += diffuseImage.point(i,j).r;
			albedo[1] += diffuseImage.point(i,j).g;
			albedo[2] += diffuseImage.point(i,j).b;
		}
	}

	albedo[0] /= sum;
	albedo[1] /= sum;
	albedo[2] /= sum;

	albedo[0] = 0.45/albedo[0];
	albedo[1] = 0.45/albedo[1];
	albedo[2] = 0.45/albedo[2];

	printf("%f %f %f\n",albedo[0],albedo[1],albedo[2]);

	for (int i=0;i<specularImage.sizex;i++)
	{
		for (int j=0;j<specularImage.sizey;j++)
		{
			output.point(i,j).r = specularImage.point(i,j).r * albedo[0];
			output.point(i,j).g = specularImage.point(i,j).g * albedo[1];
			output.point(i,j).b = specularImage.point(i,j).b * albedo[2];
		}
	}

	output.SavePFM("SpecAlbedo60.pfm");


}